package com.encon.projecttracker.server.services;

import org.springframework.security.annotation.Secured;

import com.encon.projecttracker.server.data.pojo.Session;

/**
 * Manages the operations on the GUI and persists it's current
 * selections. 
 * 
 * @author Luc Boudreau
 */
public interface SessionService extends Service {

	/**
	 * Validates that a user session id is valid. 
	 * @param userId The owner of the session
	 * @param sessionId The session unique id
	 * @throws SecurityException If either the userId or the sessionId are invalid.
	 */
	public void validateSession(String userId, String sessionId) 
	    throws SecurityException;
	
	/**
	 * Validates that this userId exists.
	 * @param userId The user unique id to validate.
	 * @throws SecurityException If this user doesn't exist.
	 */
	public void validateUser(String userId) throws SecurityException;
	
	
	/**
	 * Creates a new session space.
	 * @param userId The owner of the session to create.
	 * @return The session unique ID.
	 */
	@Secured ({"Users"})
	public String createNewSession(String userId);
	
	/**
	 * Closes and deletes a session.
	 * @param userId The owner of the session to close.
	 * @param sessionId The session id we want to close.
	 */
	@Secured ({"Users"})
	public void releaseSession(String userId, String sessionId);
	
	/**
	 * Accesses a session object directly.
	 * @param userId The owner of the required session.
	 * @param sessionId The id of the session we want.
	 * @return The session object, null if none found.
	 */
	@Secured ({"ROLE_ADMIN"})
    Session getSession(String userId, String sessionId);

	
	/**
	 * Stores an object in the user session space for later use.
	 * @param userId The owner of the session into which we want to store.
	 * @param sessionId The id of the session into which to store the variable.
	 * @param key The key under which to store the variable.
	 * @param value The object to store into the session space.
	 */
	@Secured ({"Users"})
	public void saveUserSessionVariable(String userId, String sessionId, 
		String key, Object value);
	
	/**
	 * Retreives a session variable object.
	 * @param userId The owner of the session.
	 * @param sessionId The session od from which we want a variable retreived.
	 * @param key The key under which the variable is stored.
	 * @return The stored object, null if none found.
	 */
	@Secured ({"Users"})
	public Object getUserSessionVariable(String userId, String sessionId, 
			String key);
	
	/**
	 * Removes a session variable object from the session space.
	 * @param userId The owner of the session.
	 * @param sessionId The id of the session that contains the variable.
	 * @param key The key under which the variable is stored.
	 */
	@Secured ({"Users"})
	public void deleteUserSessionVariable(String userId, String sessionId, 
		String key);
}
